package com.work.order.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

@LocalTCC
public interface IOrderService {
    /**
     * 下单：创建订单、减库存，涉及到两个服务
     *
     * @param userId
     * @param commodityCode
     * @param count
     * @param tag commit接口如果入参是[成功]，不抛出异常，[失败]，抛出异常
     */
     @TwoPhaseBusinessAction(name = "placeOrder", commitMethod = "busCommit", rollbackMethod = "busRollback", useTCCFence = true)
    void placeOrder(
             @BusinessActionContextParameter(paramName = "userId")
            String userId,
             @BusinessActionContextParameter(paramName = "commodityCode")
            String commodityCode,
             @BusinessActionContextParameter(paramName = "count")
            Integer count,
            String tag);

    void create(String userId, String commodityCode, Integer count);

    /**
     * 提交事务
     *
     * @param actionContext
     * @return
     */
    boolean busCommit(BusinessActionContext actionContext);

    /**
     * 回滚事务
     *
     * @param actionContext
     * @return
     */
    boolean busRollback(BusinessActionContext actionContext);
}
